You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After performing strict_loading! on a model with polymorphic relationships, loading the related model raises an ArgumentError. However, it seems to me that ActiveRecord::StrictLoadingViolationError should be raised.
# frozen_string_literal: truerequire"bundler/inline"gemfile(true)dosource"https://rubygems.org"git_source(:github){ |repo| "https://github.com/#{repo}.git"}# Activate the gem you are reporting the issue against.gem"activerecord",ENV.fetch('RAILS_VERSION',"~> 7.0.0")gem"sqlite3"endrequire"active_record"require"minitest/autorun"require"logger"# This connection will do for database-independent bug reports.ActiveRecord::Base.establish_connection(adapter: "sqlite3",database: ":memory:")ActiveRecord::Base.logger=Logger.new(STDOUT)ActiveRecord::Schema.definedocreate_table:posts,force: truedo |t|
endcreate_table:comments,force: truedo |t|
t.belongs_to:target,polymorphic: trueendendclassPost < ActiveRecord::Basehas_many:comments,as: :targetendclassComment < ActiveRecord::Basebelongs_to:target,polymorphic: trueendclassBugTest < Minitest::Testdeftest_strict_loading_to_polymofic_modelpost=Post.create!Comment.create!(target: post)comment=Comment.lastcomment.strict_loading!error=assert_raises(ArgumentError){comment.target}assert_equalerror.message,'Polymorphic associations do not support computing the class.'endend
Below is the repository from which the above reproduced code was pushed.
Steps to reproduce
After performing
strict_loading!
on a model with polymorphic relationships, loading the related model raises anArgumentError
. However, it seems to me thatActiveRecord::StrictLoadingViolationError
should be raised.Below is the repository from which the above reproduced code was pushed.
https://github.com/madogiwa0124/strict_loading_polymorphic_model_error_demo
Expected behavior
Raise
ActiveRecord::StrictLoadingViolationError
.Actual behavior
Raise
ArgumentError
System configuration
Rails version: 6.1.5, 7.0.2.3
Ruby version: 2.7, 3.0, 3.1
Here are the reproduced verification results of the above combination in my repository
https://github.com/madogiwa0124/strict_loading_polymorphic_model_error_demo/actions/runs/2142890874
The text was updated successfully, but these errors were encountered: